/*
 * contactable 1.2.1 - jQuery Ajax contact form
 *
 * Copyright (c) 2009 Philip Beel (http://www.theodin.co.uk/)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * Revision: $Id: jquery.contactable.js 2010-01-18 $
 *
 */
 
//extend the plugin
(function($){

	//define the new for the plugin ans how to call it	
	$.fn.contactable = function(options) {
		//set default options  
		var defaults = {
			url: 'http://YourServerHere.com/contactable/mail.php',
			name: 'Club Member Login',
			email: 'Email',
			message : 'Message',
			subject : 'A contactable message',
			submit : 'LOGIN',
			recievedMsg : 'Thank you for your message',
			notRecievedMsg : 'Sorry but your message could not be sent, try again later',
			disclaimer: 'Please feel free to get in touch, we value your feedback',
			hideOnSubmit: false

		};

		//call in the default otions
		var options = $.extend(defaults, options);
		//act upon the element that is passed into the design    
		return this.each(function() {
			//construct the form
			var this_id_prefix = '#'+this.id+' ';
			$(this).html('	<div id="contactable_inner"></div>'
					+'<html:form method="post" action="/userLogin.do?method=login"'
					+'styleId="contactForm">'
					+'<div id="loading"></div>'

					+'<div id="callback"></div>'
					+'<div class="holder">'
					+'<label for="name">'+options.name+'<span class="red"> * </span> </label><br /> <br />'
					+'<label> Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>'

					+'<html:text property="name" styleClass="field" />'
					+'<br /> <label>Password</label>'
					+'<html:password property="password" maxlength="20" size="32"'
					+'	styleClass="field" />'
					+'<br />'
					+'<html:submit value="Login" styleClass="submit" styleId="loginHref"></html:submit>'
					+'</div>'
					+'</html:form>');
			//show / hide function
			$(this_id_prefix+'div#contactable_inner').toggle(function() {
				$(this_id_prefix+'#overlay').css({display: 'block'});
				$(this).animate({"marginLeft": "-=5px"}, "fast"); 
				$(this_id_prefix+'#contactForm').animate({"marginLeft": "-=0px"}, "fast");
				$(this).animate({"marginLeft": "+=286px"}, "slow"); 
				$(this_id_prefix+'#contactForm').animate({"marginLeft": "+=290px"}, "slow"); 
			}, 
			function() {
				$(this_id_prefix+'#contactForm').animate({"marginLeft": "-=290px"}, "slow");
				$(this).animate({"marginLeft": "-=286px"}, "slow").animate({"marginLeft": "+=5px"}, "fast"); 
				$(this_id_prefix+'#overlay').css({display: 'none'});
			});
		});
	};
 
})(jQuery);
